<?php $baseURL = Zend_Controller_Front::getInstance()->getBaseUrl(); ?>
<script type="text/javascript" language="javascript" src="<?php echo $baseURL.'/tiny_mce/tiny_mce.js';  ?>"></script>
<script type="text/javascript" language="javascript" src="<?php echo $baseURL.'/js/commonfunctions.js';  ?>"></script>
<script type="text/javascript" language="javascript">
tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});

    $(document).ready(function()
    {
        $('#nameBook').change(setIsChange);
        $('#listCategory').change(setIsChange);

        $('#listAuthor').change(resetNameAuthor);
        $('#txtAuthor').change(resetListAuthor);

        $('#chNewBook').change(setIsChange);
        $('#chBestSeller').change(setIsChange);
        $('#txtPublisher').change(setIsChange);
        $('#txtYearPublisher').change(setIsChange);
        $('#file_upload').change(setIsChange);
        $('#txtCost').change(setIsChange);
        $('#txtSaleOff').change(setIsChange);
        $('#quoteContent').change(setIsChange);
        $('#introContent').change(setIsChange);
        $('#txtDateAdd').change(setIsChange);

    }
    );

    function setIsChange()
    {
        $('#isChange').val('1');
    }
    function resetNameAuthor()
    {
        $('#txtAuthor').val('');
        setIsChange();
        //alert('reset name author.')
    }
    function resetListAuthor()
    {
        $('#listAuthor').val('0');
        setIsChange();
        //alert('reset list author.')
    }
    function standardInput()
    {
        $('#nameBook').val(StandardString($('#nameBook').val()));

        $('#txtAuthor').val(StandardString($('#txtAuthor').val()));
        $('#txtPublisher').val(StandardString($('#txtPublisher').val()));
        $('#txtYearPublisher').val(StandardString($('#txtYearPublisher').val()));
        $('#txtCost').val(StandardString($('#txtCost').val()));
        $('#txtSaleOff').val(StandardString($('#txtSaleOff').val()));
        $('#txtDateAdd').val(StandardString($('#txtDateAdd').val()));
        
        return true;
    }
</script>

<div class="border">
    <div class="content">
        <h4 class="header" id="name_action">
           Thêm sách mới
        </h4>
        <div>
            <form action="<?php echo $baseURL . '/admin/book/index' ?>" method="post" enctype="multipart/form-data">
                <input type="hidden" id="current_action" name="current_action" value="<?php echo $this->current_action; ?>"/>
                <input type="hidden" id="idBook" name="idBook" value="<?php echo $this->idBook; ?>"/>
                <input type="hidden" id="isChange" name="isChange" value="<?php echo $this->isChange; ?>"/>
                <p <?php if($this->warning!='') echo 'style="padding-left:260px; border:solid 1px #3399ff"';  ?>>
                    <span class="warning"><?php echo $this->warning; ?></span>
                </p>
            <table class="common" cellpadding="0" cellspacing="0" width="98%">
                <tr>
                    <td class="title">
                        Tên sách:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="text" id="nameBook" name="nameBook" class="txt"
                          value="<?php echo $this->nameBook; ?>"      />
                        
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Tác giả:<span class="warning">*</span>
                    </td>
                    <td>
                        <select id="listAuthor" name="listAuthor">
                            <?php
                                if($this->idAuthorSelect=="0")
                                {
                                    echo '<option value="0" selected="selected">--Chọn tác giả--</option>';
                                }
                                else
                                    echo '<option value="0">--Chọn tác giả--</option>';
                                foreach($this->authors as $author)
                                {
                                    if($this->idAuthorSelect==$author["_id"])
                                    {
                                        echo '<option value="'.$author["_id"].'" selected="selected">'.$author["name"].'</option>';
                                    }
                                    else
                                        echo '<option value="'.$author["_id"].'">'.$author["name"].'</option>';
                                }
                            ?>
                        </select>
                        <br/>
                        Nhập mới:<br/>
                        <input type="text" id="txtAuthor" name="txtAuthor" class="txt"
                         value="<?php  echo $this->nameNewAuthor; ?>"      />
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Thể loại:<span class="warning">*</span>
                    </td>
                    <td>
                        <select id="listCategory" name="listCategory">
                            <?php
                                if($this->idCatSelect=="0")
                                {
                                    echo '<option value="0" selected="selected">--Chọn danh mục--</option>';
                                }
                                else
                                    echo '<option value="0">--Chọn thể loại--</option>';
                                foreach($this->cats as $cat)
                                {
                                    if($this->idCatSelect==$cat["_id"])
                                    {
                                        echo '<option value="'.$cat["_id"].'" selected="selected">'.$cat["name"].'</option>';
                                    }
                                    else
                                        echo '<option value="'.$cat["_id"].'">'.$cat["name"].'</option>';
                                }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Nhóm sách:
                    </td>
                    <td>
                        <input type="checkbox" id="chNewBook" name="chNewBook" <?php  if($this->isNewBook=='on') echo "CHECKED"; ?>/>Là sách mới<br/>
                        <input type="checkbox" id="chBestSeller" name="chBestSeller" <?php if($this->isBestSeller) echo "CHECKED"; ?>/>Là sách nổi tiếng
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Nhà xuất bản:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="text" id="txtPublisher" name="txtPublisher" class="txt"
                         value="<?php echo $this->publisher; ?>"      />
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Năm xuất bản:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="text" id="txtYearPublisher" name="txtYearPublisher" class="txt"
                         value="<?php echo $this->datePublish; ?>"      />
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Ảnh bìa:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="file" id="file_upload" name="file_upload"/>
                        <input type="hidden" name="MAX_FILE_SIZE" value="5000000"/>
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Giá sách:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="text" id="txtCost" name="txtCost" class="txt"
                         value="<?php echo $this->cost; ?>"      />
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Phần trăm giảm giá:
                    </td>
                    <td>
                        <input type="text" id="txtSaleOff" name="txtSaleOff" class="txt"
                         value="<?php echo $this->saleOff; ?>"      />
                    </td>
                </tr>
                <tr>
                    <td class="title" width="20%">
                        Các lời phê bình:
                    </td>
                    <td width="640px">
                        <textarea id="quoteContent" name="quoteContent" style="width:100%;">
                            <?php echo $this->quote; ?>
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Thông tin giới thiệu:<span class="warning">*</span>
                    </td>
                    <td width="640px">
                        <textarea id="introContent" name="introContent" style="width:100%;">
                            <?php echo $this->intro; ?>
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        Ngày nhập sách:<span class="warning">*</span>
                    </td>
                    <td>
                        <input type="text" id="txtDateAdd" name="txtDateAdd" class="txt"
                         value="<?php echo $this->dateAdd; ?>"      />(ngày/tháng/năm)
                    </td>
                </tr>
                <tr>
                    <td class="title">
                        &nbsp;
                    </td>
                    <td>
                        <input onclick="return standardInput();" type="submit" value="Submit"/>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
            </table>
            </form>
        </div>
        <div class="clear"></div>
    </div>
</div>